csv-core
A fast CSV reader and write for use in a no_std
context. This crate will
never use the Rust standard library.
Dual-licensed under MIT or the UNLICENSE.
Documentation
Usage
Add this to your Cargo.toml
:
[]
= "0.1.6"
Build features
This crate by default links with libc
, which is done via the libc
feature.
Disabling this feature will drop csv-core
's dependency on libc
.
Example: reading CSV
This example shows how to count the number of fields and records in CSV data.
use ;
let data = "
foo,bar,baz
a,b,c
xxx,yyy,zzz
";
let mut rdr = new;
let mut bytes = data.as_bytes;
let mut count_fields = 0;
let mut count_records = 0;
loop
assert_eq!;
assert_eq!;
Example: writing CSV
This example shows how to use the Writer
API to write valid CSV data. Proper
quoting is handled automatically.
use Writer;
// This is where we'll write out CSV data.
let mut out = &mut ;
// The number of bytes we've written to `out`.
let mut nout = 0;
// Create a CSV writer with a default configuration.
let mut wtr = new;
// Write a single field. Note that we ignore the `WriteResult` and the number
// of input bytes consumed since we're doing this by hand.
let = wtr.field;
nout += n;
// Write a delimiter and then another field that requires quotes.
let = wtr.delimiter;
nout += n;
let = wtr.field;
nout += n;
let = wtr.terminator;
nout += n;
// Now write another record.
let = wtr.field;
nout += n;
let = wtr.delimiter;
nout += n;
let = wtr.field;
nout += n;
// We must always call finish once done writing.
// This ensures that any closing quotes are written.
let = wtr.finish;
nout += n;
assert_eq!;